import request from '../utils/request';

const service = {};

service.createHost = data => {
  return request({
    url: `/hostinfo`,
    method: 'post',
    data
  });
};

service.updateHost = data => {
  return request({
    url: `/hostinfo`,
    method: 'put',
    data
  });
};

service.queryHosts = (index, size, appid) => {
  return request({
    url: `/hostinfo?page=${index}&pagesize=${size}&appid=${appid}`,
    method: 'get'
  });
}


service.createApp = data => {
  return request({
    url: `/appinfo`,
    method: 'post',
    data
  });
}

service.updateApp = data => {
  return request({
    url: `/appinfo`,
    method: 'put',
    data
  });
}

service.getApps = () => {
  return request({
    url: `/appinfodetail`,
    method: 'get'
  });
}

service.getAppsAndDevs = (index, size) => {
  return request({
    url: `/appinfo?page=${index}&pagesize=${size}`,
    method: 'get'
  });
}

service.querySQLSummaryInfos = (index, size, dbtype, appid, fulltablescan, status) => {
  return request({
    url: `/databaseslowsql?page=${index}&pagesize=${size}&dbtype=${dbtype}&appid=${appid}&fulltablescan=${fulltablescan}&status=${status}`,
    method: 'get'
  });
}
service.createSQLSummaryInfo = data => {
  return request({
    url: `/databaseslowsql`,
    method: 'post',
    data
  });
}

service.updateSQLSummaryInfo = data => {
  return request({
    url: `/databaseslowsql`,
    method: 'put',
    data
  });
}

service.getHostAccounts = hostid => {
  return request({
    url: `/hostpwdinfo?hostid=${hostid}`,
    method: 'get'
  });
}

service.createHostAccount = data => {
  return request({
    url: `/hostpwdinfo`,
    method: 'post',
    data
  });
}

service.updateHostAccount = data => {
  return request({
    url: `/hostpwdinfo`,
    method: 'put',
    data
  });
}

service.deleteHostAccount = id => {
  return request({
    url: `/hostpwdinfo?id=${id}`,
    method: 'delete'
  });
}

service.getDbAccounts = hostid => {
  return request({
    url: `/databasepasswd?hostid=${hostid}`,
    method: 'get'
  });
}

service.createDbAccount = data => {
  return request({
    url: `/databasepasswd`,
    method: 'post',
    data
  });
}

service.updateDbAccount = data => {
  return request({
    url: `/databasepasswd`,
    method: 'put',
    data
  });
}

service.deleteDbAccount = id => {
  return request({
    url: `/databasepasswd?id=${id}`,
    method: 'delete'
  });
}

export default service;
